﻿namespace jzgl
{
    using jzgl.Controller;
    using jzgl.Model;
    using jzgl.Properties;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class Login : Form
    {
        private Button btn_Denglu;
        private Button btn_TuiChu;
        public ComboBox comboBox1;
        private IContainer components = null;
        private Label label1;
        private Label label2;
        private Label label3;
        private Panel panel1;
        private PictureBox pictureBox1;
        private int t = 0;
        private TextBox txt_pwd;
        private SysUser user = new SysUser();
        private SysUserDB userDB = new SysUserDB();

        public Login()
        {
            this.InitializeComponent();
            this.ComboBox_Bind();
        }

        private void btn_Denglu_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txt_pwd.Text.Trim().Equals(""))
                {
                    MessageBox.Show("密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.user._UserName = this.comboBox1.Text.Trim();
                    this.user._UserPassword = this.txt_pwd.Text.Trim();
                    this.t = this.userDB.Is_UserExist(this.user);
#if DEBUG
                    this.t = 1;
#endif                     
                    if (this.t != 0)
                    {
                        new Main(this.comboBox1.Text.Trim()).Show();
                        this.Visible = false;
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_TuiChu_Click(object sender, EventArgs e)
        {
            try
            {
                base.Dispose();
                Application.Exit();
            }
            catch (Exception)
            {
            }
        }

        public void ComboBox_Bind()
        {
            try
            {
                this.userDB.Show_SysUser(this.comboBox1);
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(Login));
            this.panel1 = new Panel();
            this.comboBox1 = new ComboBox();
            this.txt_pwd = new TextBox();
            this.btn_TuiChu = new Button();
            this.btn_Denglu = new Button();
            this.label3 = new Label();
            this.label2 = new Label();
            this.label1 = new Label();
            this.pictureBox1 = new PictureBox();
            this.panel1.SuspendLayout();
            ((ISupportInitialize)this.pictureBox1).BeginInit();
            base.SuspendLayout();
            this.panel1.Controls.Add(this.comboBox1);
            this.panel1.Controls.Add(this.txt_pwd);
            this.panel1.Controls.Add(this.btn_TuiChu);
            this.panel1.Controls.Add(this.btn_Denglu);
            this.panel1.Controls.Add(this.label3);
            this.panel1.Controls.Add(this.label2);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Controls.Add(this.pictureBox1);
            this.panel1.Location = new Point(-1, 4);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(310, 0x9d);
            this.panel1.TabIndex = 0;
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new Point(0x9a, 0x17);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new Size(100, 20);
            this.comboBox1.TabIndex = 0;
            this.txt_pwd.Location = new Point(0x9a, 0x3b);
            this.txt_pwd.Name = "txt_pwd";
            this.txt_pwd.Size = new Size(100, 0x15);
            this.txt_pwd.TabIndex = 1;
            this.txt_pwd.UseSystemPasswordChar = true;
            this.btn_TuiChu.Location = new Point(0xb3, 0x7b);
            this.btn_TuiChu.Name = "btn_TuiChu";
            this.btn_TuiChu.Size = new Size(0x4b, 0x17);
            this.btn_TuiChu.TabIndex = 3;
            this.btn_TuiChu.Text = "取 消(&C)";
            this.btn_TuiChu.UseVisualStyleBackColor = true;
            this.btn_TuiChu.Click += new EventHandler(this.btn_TuiChu_Click);
            this.btn_Denglu.Location = new Point(0x54, 0x7b);
            this.btn_Denglu.Name = "btn_Denglu";
            this.btn_Denglu.Size = new Size(0x4b, 0x17);
            this.btn_Denglu.TabIndex = 2;
            this.btn_Denglu.Text = "登  录(&L)";
            this.btn_Denglu.UseVisualStyleBackColor = true;
            this.btn_Denglu.Click += new EventHandler(this.btn_Denglu_Click);
            this.label3.AutoSize = true;
            this.label3.ForeColor = Color.Silver;
            this.label3.Location = new Point(-2, 0x5c);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x143, 12);
            this.label3.TabIndex = 4;
            this.label3.Text = "_____________________________________________________";
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x66, 0x3e);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x35, 12);
            this.label2.TabIndex = 2;
            this.label2.Text = "密  码：";
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0x66, 0x1a);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x35, 12);
            this.label1.TabIndex = 1;
            this.label1.Text = "用户名：";
            this.pictureBox1.Image = Resources.LogOff;
            this.pictureBox1.Location = new Point(0x1b, 0x15);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Size(0x36, 0x3b);
            this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            base.AcceptButton = this.btn_Denglu;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            //            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x133, 0xa8);
            base.Controls.Add(this.panel1);
            base.Icon = (Icon)manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            this.MaximumSize = new Size(0x13b, 200);
            this.MinimumSize = new Size(0x13b, 200);
            base.Name = "Login";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "登录系统";
            base.Load += new EventHandler(this.Login_Load);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            ((ISupportInitialize)this.pictureBox1).EndInit();
            base.ResumeLayout(false);
        }

        private void Login_Load(object sender, EventArgs e)
        {
        }
    }
}

